package com.atguigu.day20.notify03.n3;

//todo 厨师线程
public class CookThread extends Thread {

    private Bar bar;

    public CookThread(Bar bar) {
        this.bar = bar;
    }

    @Override
    public void run() {
        while (true) {
            //厨师线程 做菜  如果吧台上菜的数量==10  厨师等待
            synchronized (bar) {
                //1.厨师判断菜的数量 >=10 等待
                while (bar.count>= Bar.MAX_COUNT){
                    try {
                        bar.wait();
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
                //2.做菜
                bar.count++;
                //展示
                System.out.println(getName() + " 做了一道菜,吧台上有[" + bar.count + "]道菜");
                //3.通知服务员上菜
                bar.notifyAll();
            }
        }
    }
}
